<?php
class Crypto {
    private static $key = 'your-secret-key-123'; // 加密密钥
    private static $cipher = 'aes-256-cbc'; // 加密算法

    public static function encrypt($data) {
        $ivlen = openssl_cipher_iv_length(self::$cipher);
        $iv = openssl_random_pseudo_bytes($ivlen);
        $encrypted = openssl_encrypt(
            json_encode($data),
            self::$cipher,
            self::$key,
            0,
            $iv
        );
        return base64_encode($iv . $encrypted);
    }

    public static function decrypt($data) {
        $data = base64_decode($data);
        $ivlen = openssl_cipher_iv_length(self::$cipher);
        $iv = substr($data, 0, $ivlen);
        $encrypted = substr($data, $ivlen);
        $decrypted = openssl_decrypt(
            $encrypted,
            self::$cipher,
            self::$key,
            0,
            $iv
        );
        return json_decode($decrypted, true);
    }
}
?> 